<%--
  Created by IntelliJ IDEA.
  User: alen
  Date: 2024/8/16
  Time: 8:56
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>修改图书信息</title>
        <%
        String base = request.getContextPath() + "/";
        System.out.println(base);
        String url = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + base;
        System.out.println(url);
    %>
    <base href="<%=url%>">
    <script type="text/javascript" src="js/jquery-1.8.3%20.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            //窗体加载后，发送异步请求
            var bookid = $("[name='hiddentxt']").val();
            $.get("book/queryById", {"bookid":bookid}, function (book) {
                JSON.stringify(book);
                $("[name='bookname']").val(book.bookname);
                $("[name='bookauthor']").val(book.bookauthor);
                $("[name='bookpublish']").val(book.bookpublish);
                $("[name='bookpage']").val(book.bookpage);
                $("[name='bookprice']").val(book.bookprice);
                $("[name='createdate']").val(book.createdate);
            });
            //窗体加载后，提交按钮单击事件，发起异步请求
            $("[type='button']").click(function () {
                var bookid = $("[name='hiddentxt']").val();
                var bookname = $("[name='bookname']").val();
                var bookauthor = $("[name='bookauthor']").val();
                var bookpublish = $("[name='bookpublish']").val();
                var bookpage = $("[name='bookpage']").val();
                var bookprice = $("[name='bookprice']").val();
                var createdate = $("[name='createdate']").val();

                $.get("book/update", {
                    "bookid":bookid,
                    "bookname":bookname,
                    "bookauthor":bookauthor,
                    "bookpublish":bookpublish,
                    "bookpage":bookpage,
                    "bookprice":bookprice,
                    "createdate":createdate
                }, function (mess) {
                    JSON.stringify(mess);
                    if (mess)
                        alert("修改成功");
                    else
                        alert("修改失败");
                });
            });
        });
    </script>
</head>
<body>
    <a href="index.jsp">返回</a>
    <h1>修改图书</h1>
    书名：<input type="text" name="bookname"><br/>
    作者：<input type="text" name="bookauthor"><br/>
    出版社：<input type="text" name="bookpublish"><br/>
    页数：<input type="text" name="bookpage"><br/>
    价格：<input type="text" name="bookprice"><br/>
    创建时间：<input type="date" name="createdate"><br/>
    <input type="button" value="提交"><br/>

<input type="hidden" name="hiddentxt" value="<%=request.getParameter("bookid")%>">
</body>
</html>
